package cz.schovjan.mte_proj.activity;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import cz.schovjan.mte_proj.Constant;
import cz.schovjan.mte_proj.R;
import cz.schovjan.mte_proj.dto.Artist;
import cz.schovjan.mte_proj.dto.LyricResult;
import cz.schovjan.mte_proj.service.Database;
import cz.schovjan.mte_proj.service.DatabaseImpl;

public class LyricActivity extends Activity {

    private LyricResult lr;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_lyric);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
	// Inflate the menu; this adds items to the action bar if it is present.
	getMenuInflater().inflate(R.menu.lyric, menu);
	return true;
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	    case R.id.menu_search_video:
		Intent va = new Intent(this, VideoActivity.class);
		va.putExtra(Constant.LYRIC, ((LyricResult) lr));
		startActivity(va);
		return true;
	    default:
		return super.onOptionsItemSelected(item);
	}
    }


    @Override
    protected void onStart() {
	super.onStart();
	EditText et = (EditText) findViewById(R.id.editLyric);
	lr = getIntent().getParcelableExtra(Constant.LYRIC);
	et.setText(lr.getText());
	// test db
	Database db = new DatabaseImpl(this);
	Log.i(Constant.TAG, "vkladam artistu");
	db.addArtist(lr);
	Log.i(Constant.TAG, "vypisuju vsechny artisty");
	List<Artist> as = db.findAllArtist();
	for (Artist a : as) {
	    Log.i(Constant.TAG, a.toString());
	}
    }
}
